package com.wdh.kjs.activity;

import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.wdh.kjs.R;
import com.wdh.kjs.model.data;
import com.wdh.kjs.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by CQH on 2016/4/21.
 */
public class UploadProjectInfoActivity extends BaseTopActivity implements View.OnClickListener {
    private Intent intent;
    private LinearLayout upload_file_per_jichuxinxi;
    private LinearLayout upload_file_per_2;
    private LinearLayout upload_file_per_3;
    private LinearLayout upload_file_per_4;
    private LinearLayout upload_file_per_5;
    private Button bt_makesure;
    private TextView tv_jichuxinxinumber;
    private TextView tv_cailizhengming;
    private TextView tv_lawprove;
    private TextView tv_otherprove;
    private TextView tv_zhengxinzhengming;
    private SharedPreferences sharedPreferences;

    private String othersize;
    private String jichusize;
    private String lawsize;
    private String moneysize;
    private String zhengxinsize;

    private List<String> idList = new ArrayList<>();
    private List<String> cailiList = new ArrayList<>();
    private List<String> law = new ArrayList<>();
    private List<String> other = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.upload_file_per);
        initTopBar("上传资料");
        initview();
        initwidge();

    }

    private void initwidge() {
        sharedPreferences = getSharedPreferences("zhaopian", MODE_PRIVATE);
        jichusize = sharedPreferences.getString("jichusize", "0");
        othersize = sharedPreferences.getString("othersize", "0");
        lawsize = sharedPreferences.getString("lawsize", "0");
        zhengxinsize = sharedPreferences.getString("zhengxinsize", "0");
        moneysize = sharedPreferences.getString("moneysize", "0");
        tv_jichuxinxinumber.setText("已有" + jichusize + "个文件");
        tv_otherprove.setText("已有" + othersize + "个文件");
        tv_lawprove.setText("已有" + lawsize + "个文件");
        tv_cailizhengming.setText("已有" + moneysize + "个文件");
        tv_zhengxinzhengming.setText("已有" + zhengxinsize + "个文件");
    }

    @Override
    protected void onResume() {
        super.onResume();
        initwidge();
    }

    private void initview() {
        tv_zhengxinzhengming = (TextView) findViewById(R.id.tv_zhengxinzhengming);
        tv_otherprove = (TextView) findViewById(R.id.tv_otherprove);
        tv_lawprove = (TextView) findViewById(R.id.tv_lawprove);
        tv_cailizhengming = (TextView) findViewById(R.id.tv_cailizhengming);
        tv_jichuxinxinumber = (TextView) findViewById(R.id.tv_jichuxinxinumber);
        bt_makesure = (Button) findViewById(R.id.bt_makesure);
        bt_makesure.setOnClickListener(this);
        upload_file_per_jichuxinxi = (LinearLayout) findViewById(R.id.upload_file_per_jichuxinxi);
        upload_file_per_jichuxinxi.setOnClickListener(this);
        upload_file_per_2 = (LinearLayout) findViewById(R.id.upload_file_per_2);
        upload_file_per_2.setOnClickListener(this);
        upload_file_per_3 = (LinearLayout) findViewById(R.id.upload_file_per_3);
        upload_file_per_3.setOnClickListener(this);
        upload_file_per_4 = (LinearLayout) findViewById(R.id.upload_file_per_4);
        upload_file_per_4.setOnClickListener(this);
        upload_file_per_5 = (LinearLayout) findViewById(R.id.upload_file_per_5);
        upload_file_per_5.setOnClickListener(this);
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_makesure:
                if (jichusize.equals("0")) {
                    falseDialogShow("请上传基础信息");
                } else if (lawsize.equals("0")) {
                    falseDialogShow("请上传相关法律材料");
                } else if (moneysize.equals("0")) {
                    falseDialogShow("请上传财力证明");
                } else if (zhengxinsize.equals("0")) {
                    falseDialogShow("请上传征信证明");
                } else {
                    for (int i = 0; i < cailiList.size(); i++) {
                        idList.add(cailiList.get(i));
                    }
                    for (int i = 0; i < law.size(); i++) {
                        idList.add(law.get(i));
                    }
                    for (int i = 0; i < other.size(); i++) {
                        idList.add(other.get(i));
                    }
                    intent = new Intent();
                    intent.setClass(UploadProjectInfoActivity.this, RongziActivity.class);
                    intent.putStringArrayListExtra("jiben", (ArrayList<String>) idList);

                    setResult(1, intent);
                    finish();
                }
                break;
            case R.id.upload_file_per_jichuxinxi:
                intent = new Intent(this, BaseMessagePushActivity.class);

                startActivityForResult(intent, 1);

                break;
            case R.id.upload_file_per_2:
                intent = new Intent(this, MoneyProveActivity.class);

                startActivityForResult(intent, 4);
                break;
            case R.id.upload_file_per_3:
                intent = new Intent(this, ZhengxinZMActivity.class);

                startActivityForResult(intent, 3);
                break;
            case R.id.upload_file_per_4:
                intent = new Intent(this, LawProveActivity.class);

                startActivityForResult(intent, 7);
                break;

            case R.id.upload_file_per_5:
                intent = new Intent(this, OtherProveActivity.class);

                startActivityForResult(intent, 8);
                break;

        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == 1) {
            idList = data.getStringArrayListExtra("jiben");
            String size = data.getStringExtra("size");
            int jichusize = Integer.parseInt(size) - 1;
            tv_jichuxinxinumber.setText("已有" + jichusize + "个文件");
        }
        if (resultCode == 4) {
            cailiList = data.getStringArrayListExtra("caili");
//            tv_cailizhengming.setText("已有"+cailiList.size()+"个文件");
        }
        if (resultCode == 7) {
            law = data.getStringArrayListExtra("law");
//            tv_lawprove.setText("已有"+law.size()+"个文件");
        }
        if (resultCode == 8) {
            other = data.getStringArrayListExtra("other");
//            tv_otherprove.setText("已有" + other.size()+"个文件");
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    private void falseDialogShow(String hint) {
        View dialog = getLayoutInflater().inflate(R.layout.touzixinxi, null);
//        Button bt_dialog_false_negative = (Button) dialog.findViewById(R.id.bt_dialog_false_negative);
//        Button bt_dialog_false_positive = (Button) dialog.findViewById(R.id.bt_dialog_false_positive);
        TextView tv_dialog_false_hint = (TextView) dialog.findViewById(R.id.touzixinxi);
        tv_dialog_false_hint.setText(hint);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(dialog);
        builder.create();
        final AlertDialog dialogShow = builder.show();
        tv_dialog_false_hint.setOnClickListener(new android.view.View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dialogShow.dismiss();
            }
        });
//        bt_dialog_false_positive.setOnClickListener(new android.view.View.OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                dialogShow.dismiss();
//            }
//        });
    }
}
